(function (j) {
	var news_recent_time = 3000;
	var news_recent_slide =  function(){
		
		as = j('#recent-nav > a');
		if (j(as).size() > 0) {
			var temp = as[as.length-1];
			j(as[0]).before(temp);
		}
		setTimeout(news_recent_slide, news_recent_time);
	}
	j(function (){
		setTimeout(news_recent_slide, news_recent_time);
		//Fix breadcrumbs.
		_html=$('.breadcrumbs').html().split('&gt;')
		_html.shift();
		$('.breadcrumbs').html(_html.join('&gt;'));
		//End fix breadcrumbs.
		
		
		
		var _rlist = $('.recomment-list');
		if (_rlist.size() > 0) {
			_rlist.children(':first').addClass('active');
			var _width = _rlist.children(':first').width();
			var control = $('.recomment-control');
			control.find('.next').click(function(){
				if (_rlist.children('.active').next().size() <= 0) 
				{
					_rlist.children('.active').removeClass('active');
					_rlist.children(':first').addClass('active');
				}else {
					_rlist.children('.active').next().addClass('active');
					_rlist.children('.active').eq(0).removeClass('active');
				}
				_rlist.animate({
					'margin-left': -(_rlist.children('.active').offset().left - _rlist.offset().left )
				});
				return false;
			});
			control.find('.prev').click(function(){
				if (_rlist.children('.active').prev().size() <= 0) {
					_rlist.children('.active').removeClass('active');
					_rlist.children(':last').addClass('active');
				}else {
					_rlist.children('.active').prev().addClass('active');
					_rlist.children('.active').eq(1).removeClass('active');
				}
				_rlist.animate({
					'margin-left': -(_rlist.children('.active').offset().left - _rlist.offset().left )
				});
				return false;
			});
		}
	});
	j.fn.getImageSize = function(){
		img =this[0];
		var t = new Image();
			t.src = (img.getAttribute ? img.getAttribute("src") : false) || img.src;
		return t;
	}
	j.fn.sliderPi = function(){
		var _slide = this;
		var viewer = j(this).find('.gallery-viewer');
		var list = j(this).find('.gallery-list');
		_slide.li_width = parseInt(list.children('li').eq(0).width()) + 5;
		_slide.li_num = list.children('li').size();
		_slide.outer_width = $(_slide).find('#g-list-outer').width();
		_slide.change = function (li) {
			v_img = viewer.find('img');	
			if (v_img.attr('src')== $(li).find('img').attr('src'))
				return false;
			$(viewer).animate({opacity: 0}, 100);
			
			v_img.attr('src', $(li).find('img').attr('src'));
			$(li).siblings().removeClass('active');
			$(li).addClass('active');
			$(viewer).animate({opacity: 1}, 500 );
		}
		_slide.slide_next= function(){
			if ($(list).children().size() <=6)
				return ;
			var left = parseInt($('.gallery-list').css('margin-left'))-  _slide.li_width;
			if (left >= 0) 
				return;
			$('.gallery-list').animate({'margin-left': left}, 500);
		}
		_slide.slide_prev= function(){
			if ($(list).children().size() <=6)
				return ;
			var left = parseInt($('.gallery-list').css('margin-left')) + _slide.li_width;
			if (-left >= (_slide.li_width * _slide.li_num) - _slide.outer_width)
				return;
				
			$('.gallery-list').animate({'margin-left': left}, 500);
		}
		if (j(list).find('li'))
		j(_slide).children('.first').click(function (){
			_slide.slide_prev();
		});
		j(_slide).children('.last').click(function (){
			_slide.slide_next();
		});
		j(viewer).children('.ctrl-prev').click(function (){
			var prev = undefined;
			if ($(list).find('.active').prev()[0] !=  list.find('li:first-child')) 
				prev= $(list).find('.active').prev();
			else {
				prev= $(list).find('.last').prev();
			}
			_slide.change(prev);
			return false;
		});
		j(viewer).children('.ctrl-next').click(function (){
			var next = undefined;
			if ($(list).find('.active').next()[0] !=  $(list).find('li.last')[0]) 
				next= $(list).find('.active').next();
			else {
				next= $(list).find('.first').next();
			}
			_slide.change(next);
			return false;
		});
		j(list).children('li').click(function() {
			if (!$(this).hasClass('first') && !$(this).hasClass('last')) {
				_slide.change(this);
			}
		});
		_slide.change(j(list).children('li:first-child'));
	}
	
	
} )(jQuery);